cmake_minimum_required(VERSION 3.10)

# 设置单元测试项目
project(BlogSystem_Tests)

# 使用Google Test框架
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# 查找MySQL和hiredis库
find_package(PkgConfig REQUIRED)
pkg_check_modules(MYSQL REQUIRED mysqlclient)
pkg_check_modules(HIREDIS REQUIRED hiredis)

# 添加测试源文件（包含所有测试文件）
set(TEST_SOURCES
    test_auth_service.cpp
    test_blog_service.cpp
    test_chat_service.cpp
    test_database.cpp
    test_network.cpp
    test_cache.cpp
    test_epoll_server.cpp
)

# 为每个测试创建可执行文件
foreach(test_source ${TEST_SOURCES})
    get_filename_component(test_name ${test_source} NAME_WE)
    add_executable(${test_name} ${test_source})
    
    # 基本库
    target_link_libraries(${test_name} 
        ${GTEST_LIBRARIES} 
        pthread 
        common_lib 
        network_lib 
        database_lib 
        cache_lib
    )
    
    # 根据测试类型添加特定库
    if(${test_name} STREQUAL "test_auth_service")
        target_link_libraries(${test_name} auth_service_lib ${MYSQL_LIBRARIES} ${HIREDIS_LIBRARIES})
    elseif(${test_name} STREQUAL "test_database")
        target_link_libraries(${test_name} ${MYSQL_LIBRARIES})
    elseif(${test_name} STREQUAL "test_cache")
        target_link_libraries(${test_name} ${HIREDIS_LIBRARIES})
    endif()
    
    add_test(NAME ${test_name} COMMAND ${test_name})
endforeach() 